$_
which
set _filename=%~n1
set _extension=%~x1
%~n1
- Expand %1
to a file Name without
file extension.%~x1
- Expand %1
to a file eXtension
only.cmd.exe /C start <file>
Note: you need to replace /mnt/c
with
C:
.
start
with
space in the pathUse an additional quotes.
start "" "Y:\foo bar\baz"
dir & echo foo
If you want the second command to execute only if the first exited successfully:
dir && echo foo
foreach($line in Get-Content .\file.txt) {
if($line -match $regex){
# Work here
}
}
The environment variable is provided by Env:
. To list
all the environment variables, do the following
Set-Location Env:
Get-ChildItem
Use the symbol |
.
For example, convert the line ending in all the markdown files in a folder to the UNIX format.
Get-ChildItem -Path .\ -Filter *.md -Recurse -File -Name | ForEach-Object { dos2unix $_ }
$MyVariable = "Some text"
Write-Host "${MyVariable}NOSPACES"
$PSCommandPath
(Get-Item $PSCommandPath ).Extension
(Get-Item $PSCommandPath ).Basename
(Get-Item $PSCommandPath ).Name
(Get-Item $PSCommandPath ).DirectoryName
(Get-Item $PSCommandPath ).FullName
$ConfigINI = (Get-Item $PSCommandPath ).DirectoryName+"\"+(Get-Item $PSCommandPath ).BaseName+".ini"
$_
This is the variable for the current value in the pipe line, which is
called $PSItem
in Powershell 3 and newer.
$PSScriptRoot
Join-Path -Path "path" -ChildPath "childpath"
Use #
Use a semicolon to chain commands in PowerShell:
ipconfig /release; ipconfig /renew
which
Get-Command
New-Item -ItemType SymbolicLink -Path "Link" -Target "Target"
In addition, you can call the mklink
provided by
cmd
, from PowerShell to make symbolic links:
cmd /c mklink c:\path\to\symlink c:\target\file
You must pass /d
to mklink
if the target is
a directory.
cmd /c mklink /d c:\path\to\symlink c:\target\directory
Try the -Force
parameter:
New-Item -ItemType Directory -Force -Path C:\Path\That\May\Or\May\Not\Exist
$OutputVariable = (Shell command)
Get the location of the history file by the following command
(Get-PSReadlineOption).HistorySavePath
Then open the path in a text editor to see the full history.
Get-History
shows only the history in the current
session.
Use the following command to check the current values of
$PROFILE
.
PS C:\Users\J.Shi> $PROFILE | Get-Member -Type NoteProperty
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
AllUsersAllHosts NoteProperty string AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost NoteProperty string AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts NoteProperty string CurrentUserAllHosts=C:\Users\J.Shi\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost NoteProperty string CurrentUserCurrentHost=C:\Users\J.Shi\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
For reference, check The $PROFILE variable.
For reference, check 使用PowerShell Profile快速设置 HTTP 代理.
This script has already saved to the PowerShell profile.
ipconfig /flushdns
set HTTP_PROXY=http://127.0.0.1:1080
IP and port should be adjusted to the real situation. Check
IE -> Internet Options -> Connections -> LAN settings
.
For Shadowsocks, it is normally http://127.0.0.1:1080
.
For Powershell, the configuration seems to be so complex.
Proxifier
to
set shadowsocks
as the global proxy使用Proxifier把shadowsocks代理转为真·全局(类VPN)
conda
connection
issueThe connection issue is as follows,
(base) C:\Users\avnis>conda update conda
Collecting package metadata (current_repodata.json): failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://repo.anaconda.com/pkgs/main/win-64/current_repodata.json
Elapsed: -
Copy the following files
libcrypto-1_1-x64.*
libssl-1_1-x64.*
from D:\Anaconda3\Library\bin
to
D:\Anaconda3\DLLs
.
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
Reference: How to set up working X11 forwarding on WSL2
First obtain the host IP:
awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null
Then set up the environment variables:
export http_proxy='http://<Windows IP>:<Port>'
export https_proxy='http://<Windows IP>:<Port>'
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
Windows Search > Network Reset
Restart Windows
The size of the virtual hard drive keeps on increasing automatically and if you delete a file from the linux file system, the space occupied by the VHD is still the same. We need a way to manually free up this space from Windows 10.
wsl --shutdown
For reference: How to rename the User folder in Windows 10?
Basically, simply rename the user folder and edit the registry.
Edit the registry. Check this link.
The Group Policy Editor is not available to any Windows Home users, be it Windows XP, Windows 7, Windows 8.1 or Windows 10.
This is a serious drawback as we need the group policies even for managing settings of the local computer. The local group policy is better than changing the settings through Windows Registry which is much riskier. Most group policy settings can revert easily, while Registry editing can have adverse effects on the system.
Use this simple PowerShell script to install the disabled Group Policy feature in the Windows 10 Home edition. Although a restart is not required, if the policies are not working, you should restart the computer once.
Open the Run dialog by pressing Windows key + R. Type
gpedit.msc
and press the Enter key or OK button. This
should open gpedit in Windows 10 Home.
Reference: How To Enable Group Policy Editor (Gpedit.Msc) In Windows 10 Home Edition
In the Local Group Policy Editor, navigate to the location
Computer Configuration\Administrative Templates\Windows Components\Search
.
Edit
Do not allow locations on removable drives to be added to libraries
to enable it.
Reference: Enable or Disable Adding Locations on Removable Drives to Index and Libraries in Windows 10
For reference, check Windows SSH: Permissions for ‘private-key’ are too open.
You locate the file in Windows Explorer, right-click on it then select “Properties”. Navigate to the “Security” tab and click “Advanced”.
Change the owner to you, disable inheritance and delete all permissions. Then grant yourself “Full control” and save the permissions. Now SSH won’t complain about file permission too open anymore.
It should end up looking like this:
Directly go to the original webpage of this CAJ. Copy the CAJ link
and replace cajdown
with pdfdown
to download a
PDF version.